$font-size-base: 16px !default;

@function remove-unit($number) {
  $unit: unit($number);
  $one: 1;

  @if $unit == "px" { $one: 1px; }
  @if $unit == "em" { $one: 1em; }
  @if $unit == "%"  { $one: 1%;  }

  @return $number / $one;
}

@function convert-to-pixel($number) {
  $unit: unit($number);

  @if $unit == "em" { @return remove-unit($number) * $font-size-base; }
  @if $unit == "px" { @return $number; }

  @return 0;
}

@function em($target, $context: $font-size-base) {
  $size: remove-unit($target) / remove-unit(convert-to-pixel($context));

  @return $size * 1em;
}
